package com.liruo.learn.spring.session.controller;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @Author:liruo
 * @Date:2023-02-15-04:04:04
 * @Desc
 */
@RestController
@Slf4j
public class DemoController {
//    @Resource
//    SessionRepository<Se> sessionRepository;
    @Resource
    RedissonClient redissonClient;
    @GetMapping("/test/session/{key}={value}")
    public void test(@PathVariable("key")String key, @PathVariable("value")String value,
                     HttpSession session){
        if(key.startsWith("set:")){
            key = key.substring("set:".length());
            session.setAttribute(key, value);
        }else if(key.startsWith("get:")){
            key = key.substring("get:".length());
            log.debug("{}", session.getAttribute(key));
        }else{
            session.setAttribute(key, value);
            log.debug("{}", session.getAttribute(key));
        }
    }
}
